<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>AI产品详情页生成 - OZON工具平台</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        @import url('https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;700&display=swap');
        
        body {
            font-family: 'Roboto', sans-serif;
            margin: 0;
            padding: 0;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: #333;
            min-height: 100vh;
            display: flex;
        }
        .sidebar {
            width: 200px;
            background-color: white;
            color: #333;
            height: 100vh;
            position: fixed;
            left: 0;
            top: 0;
            box-shadow: 2px 0 5px rgba(0,0,0,0.1);
            z-index: 100;
            overflow-y: auto;
            border-right: 1px solid #e0e0e0;
        }
        .sidebar-header {
            padding: 15px;
            background-color: #1565C0;
            text-align: left;
            font-weight: bold;
            font-size: 18px;
            border-bottom: 1px solid rgba(255,255,255,0.1);
            display: flex;
            align-items: center;
            color: white;
        }
        .sidebar-menu {
            padding: 15px 0;
        }
        .sidebar-menu-item {
            padding: 10px 15px;
            display: flex;
            align-items: center;
            color: #666;
            text-decoration: none;
            transition: background-color 0.3s;
            font-size: 14px;
        }
        .sidebar-menu-item:hover {
            background-color: rgba(0,0,0,0.05);
            color: #1565C0;
        }
        .sidebar-menu-item i {
            margin-right: 10px;
            width: 20px;
            text-align: center;
            color: #999;
        }
        .sidebar-menu-item:hover i {
            color: #1565C0;
        }
        .sidebar-breadcrumb {
            padding: 10px 15px;
            font-size: 14px;
            display: flex;
            align-items: center;
            background-color: #1976D2;
            margin-bottom: 5px;
        }
        .sidebar-breadcrumb a {
            color: rgba(255,255,255,0.8);
            text-decoration: none;
        }
        .sidebar-breadcrumb a:hover {
            color: white;
            text-decoration: underline;
        }
        .sidebar-breadcrumb .separator {
            margin: 0 8px;
            color: rgba(255,255,255,0.5);
        }
        .sidebar-breadcrumb .current {
            color: white;
            font-weight: 500;
        }
        .main-content {
            flex: 1;
            margin-left: 200px;
            padding: 20px;
        }
        .container {
            max-width: 1200px;
            margin: 0 auto;
            background-color: white;
            border-radius: 15px;
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
            overflow: hidden;
        }
        .header {
            background: linear-gradient(135deg, #667eea, #764ba2);
            color: white;
            padding: 30px;
            text-align: center;
        }
        .header h1 {
            margin: 0;
            font-size: 32px;
            font-weight: 700;
        }
        .header p {
            margin: 10px 0 0;
            font-size: 16px;
            opacity: 0.9;
        }
        .content {
            padding: 40px;
        }
        .upload-section {
            background: linear-gradient(135deg, #f8f9fa, #e9ecef);
            border: 3px dashed #667eea;
            border-radius: 15px;
            padding: 40px;
            text-align: center;
            margin-bottom: 30px;
            transition: all 0.3s ease;
            cursor: pointer;
        }
        .upload-section:hover {
            border-color: #764ba2;
            background: linear-gradient(135deg, #f0f2ff, #e8ebff);
        }
        .upload-section.dragover {
            border-color: #28a745;
            background: linear-gradient(135deg, #f0fff4, #e6ffed);
        }
        .upload-icon {
            font-size: 48px;
            color: #667eea;
            margin-bottom: 20px;
        }
        .upload-text {
            font-size: 18px;
            color: #555;
            margin-bottom: 10px;
        }
        .upload-hint {
            font-size: 14px;
            color: #777;
        }
        .file-input {
            display: none;
        }
        .form-section {
            margin-bottom: 30px;
        }
        .form-section h3 {
            color: #667eea;
            margin-bottom: 15px;
            font-size: 18px;
            font-weight: 600;
        }
        .form-group {
            margin-bottom: 20px;
        }
        .form-group label {
            display: block;
            margin-bottom: 8px;
            font-weight: 500;
            color: #555;
        }
        .form-control {
            width: 100%;
            padding: 12px 15px;
            border: 2px solid #e1e5e9;
            border-radius: 8px;
            font-size: 14px;
            transition: border-color 0.3s;
            box-sizing: border-box;
        }
        .form-control:focus {
            outline: none;
            border-color: #667eea;
            box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
        }
        .form-row {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 20px;
        }
        .watermark-section {
            background-color: #f8f9fa;
            padding: 20px;
            border-radius: 10px;
            margin-bottom: 20px;
        }
        .watermark-preview {
            width: 200px;
            height: 60px;
            border: 2px dashed #ddd;
            border-radius: 8px;
            display: flex;
            align-items: center;
            justify-content: center;
            margin-top: 10px;
            background-color: white;
            position: relative;
            overflow: hidden;
        }
        .watermark-text {
            font-weight: bold;
            color: #667eea;
            font-size: 16px;
        }
        .generate-btn {
            background: linear-gradient(135deg, #667eea, #764ba2);
            color: white;
            border: none;
            padding: 15px 40px;
            border-radius: 8px;
            font-size: 16px;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.3s;
            width: 100%;
            margin-top: 20px;
        }
        .generate-btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 10px 20px rgba(102, 126, 234, 0.3);
        }
        .generate-btn:disabled {
            opacity: 0.6;
            cursor: not-allowed;
            transform: none;
        }
        .loading {
            display: none;
            text-align: center;
            margin: 20px 0;
        }
        .loading-spinner {
            border: 3px solid #f3f3f3;
            border-top: 3px solid #667eea;
            border-radius: 50%;
            width: 40px;
            height: 40px;
            animation: spin 1s linear infinite;
            margin: 0 auto 10px;
        }
        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }
        .preview-section {
            margin-top: 30px;
            padding-top: 30px;
            border-top: 2px solid #e1e5e9;
            display: none;
        }
        .uploaded-image {
            max-width: 300px;
            max-height: 300px;
            border-radius: 10px;
            box-shadow: 0 5px 15px rgba(0,0,0,0.2);
            margin-bottom: 20px;
        }
        .result-section {
            margin-top: 30px;
            padding-top: 30px;
            border-top: 2px solid #e1e5e9;
            display: none;
        }
        .product-detail-page {
            background: white;
            border-radius: 15px;
            box-shadow: 0 10px 30px rgba(0,0,0,0.1);
            overflow: hidden;
            margin-bottom: 20px;
        }
        .product-header {
            background: linear-gradient(135deg, #f8f9fa, #e9ecef);
            padding: 30px;
            position: relative;
        }
        .brand-watermark {
            position: absolute;
            top: 20px;
            left: 20px;
            background: rgba(102, 126, 234, 0.9);
            color: white;
            padding: 8px 15px;
            border-radius: 20px;
            font-weight: bold;
            font-size: 14px;
            backdrop-filter: blur(10px);
            box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
        }
        .product-content {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 40px;
            padding: 40px;
        }
        .product-image-container {
            text-align: center;
        }
        .product-image {
            max-width: 100%;
            border-radius: 15px;
            box-shadow: 0 10px 30px rgba(0,0,0,0.2);
        }
        .product-info {
            padding: 20px 0;
        }
        .product-title {
            font-size: 28px;
            font-weight: 700;
            color: #333;
            margin-bottom: 15px;
            line-height: 1.3;
        }
        .product-price {
            font-size: 32px;
            font-weight: 700;
            color: #e74c3c;
            margin-bottom: 20px;
        }
        .product-description {
            font-size: 16px;
            line-height: 1.6;
            color: #666;
            margin-bottom: 25px;
        }
        .product-features {
            background-color: #f8f9fa;
            padding: 20px;
            border-radius: 10px;
            margin-bottom: 25px;
        }
        .feature-item {
            display: flex;
            align-items: center;
            margin-bottom: 10px;
            font-size: 14px;
        }
        .feature-item i {
            color: #28a745;
            margin-right: 10px;
            width: 16px;
        }
        .action-buttons {
            display: flex;
            gap: 15px;
            margin-top: 30px;
        }
        .btn {
            padding: 12px 25px;
            border: none;
            border-radius: 8px;
            font-size: 16px;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.3s;
            text-decoration: none;
            display: inline-flex;
            align-items: center;
            gap: 8px;
        }
        .btn-primary {
            background: linear-gradient(135deg, #667eea, #764ba2);
            color: white;
        }
        .btn-primary:hover {
            transform: translateY(-2px);
            box-shadow: 0 8px 20px rgba(102, 126, 234, 0.3);
        }
        .btn-secondary {
            background-color: #6c757d;
            color: white;
        }
        .btn-secondary:hover {
            background-color: #5a6268;
        }
        .result-actions {
            display: flex;
            gap: 15px;
            justify-content: center;
            margin-top: 30px;
            flex-wrap: wrap;
        }
        .toast {
            position: fixed;
            bottom: 20px;
            right: 20px;
            background-color: rgba(0, 0, 0, 0.8);
            color: white;
            padding: 12px 20px;
            border-radius: 6px;
            font-size: 14px;
            z-index: 1000;
            opacity: 0;
            transform: translateY(20px);
            transition: all 0.3s ease;
        }
        .toast.show {
            opacity: 1;
            transform: translateY(0);
        }
        .batch-images-container {
            margin-top: 20px;
        }
        .generated-image-item {
            background: white;
            border-radius: 15px;
            box-shadow: 0 5px 15px rgba(0,0,0,0.1);
            padding: 20px;
            margin-bottom: 20px;
            text-align: center;
        }
        .generated-image-item h4 {
            color: #667eea;
            margin-bottom: 15px;
            font-size: 18px;
        }
        .generated-image {
            max-width: 100%;
            max-height: 600px;
            border-radius: 10px;
            box-shadow: 0 5px 15px rgba(0,0,0,0.2);
            margin-bottom: 15px;
        }
        .image-actions {
            display: flex;
            justify-content: center;
            gap: 10px;
        }
        .tips {
            background-color: #e7f3ff;
            border-left: 4px solid #667eea;
            padding: 15px;
            margin-bottom: 20px;
            border-radius: 0 8px 8px 0;
        }
        .tips h4 {
            margin: 0 0 10px;
            color: #667eea;
            font-size: 16px;
        }
        .tips ul {
            margin: 0;
            padding-left: 20px;
        }
        .tips li {
            margin-bottom: 5px;
            color: #555;
        }
        @media (max-width: 768px) {
            .main-content {
                margin-left: 0;
            }
            .sidebar {
                transform: translateX(-100%);
            }
            .form-row {
                grid-template-columns: 1fr;
            }
            .product-content {
                grid-template-columns: 1fr;
                gap: 20px;
            }
            .action-buttons {
                flex-direction: column;
            }
        }
    </style>
</head>
<body>
    <div class="sidebar">
        <div class="sidebar-header">
            <span>OZON工具平台</span>
            <i class="fas fa-bars" style="margin-left: auto;"></i>
        </div>
        <div class="sidebar-menu">
            <a href="index.html" class="sidebar-menu-item"><i class="fas fa-th-large"></i> Dashboard</a>
            <div class="sidebar-breadcrumb">
                <a href="index.html">首页</a>
                <span class="separator">></span>
                <a href="ai-tools.html">AI工具</a>
                <span class="separator">></span>
                <span class="current">产品详情页生成</span>
            </div>
            <a href="index.html" class="sidebar-menu-item"><i class="fas fa-home"></i> 首页</a>
            <a href="tools.html" class="sidebar-menu-item"><i class="fas fa-tools"></i> 实用工具</a>
            <a href="ai-tools.html" class="sidebar-menu-item"><i class="fas fa-robot"></i> AI工具</a>
            <a href="data-analysis.html" class="sidebar-menu-item"><i class="fas fa-chart-line"></i> 数据分析</a>
            <a href="settings.html" class="sidebar-menu-item"><i class="fas fa-cog"></i> 设置</a>
        </div>
    </div>
    
    <div class="main-content">
        <div class="container">
            <div class="header">
                <h1><i class="fas fa-file-alt"></i> AI产品详情页生成</h1>
                <p>上传商品图片，AI智能生成现代化产品详情页，自动添加品牌水印</p>
            </div>
            
            <div class="content">
                <div class="tips">
                    <h4><i class="fas fa-lightbulb"></i> 功能特色</h4>
                    <ul>
                        <li><strong>AI图像识别：</strong>自动识别商品类型、特征和卖点</li>
                        <li><strong>智能内容生成：</strong>生成吸引人的产品标题、描述和特性</li>
                        <li><strong>现代化设计：</strong>符合当前电商平台审美趋势</li>
                        <li><strong>品牌水印：</strong>在左上角添加专业品牌标识</li>
                        <li><strong>响应式布局：</strong>适配各种设备和屏幕尺寸</li>
                    </ul>
                </div>
                
                <!-- 批量图片上传区域 -->
                <div class="upload-section" id="uploadArea" onclick="document.getElementById('fileInput').click()">
                    <div class="upload-icon">
                        <i class="fas fa-cloud-upload-alt"></i>
                    </div>
                    <div class="upload-text">点击上传商品图片（支持批量）</div>
                    <div class="upload-hint">支持 JPG、PNG、WebP 格式，建议尺寸 800x800 以上，可同时选择多张图片</div>
                    <input type="file" id="fileInput" class="file-input" accept="image/*" multiple onchange="handleFileUpload(event)">
                </div>
                
                <!-- 图片预览 -->
                <div class="preview-section" id="previewSection">
                    <h3><i class="fas fa-eye"></i> 图片预览</h3>
                    <img id="uploadedImage" class="uploaded-image" alt="上传的商品图片">
                </div>
                
                <!-- 商品信息表单 -->
                <div class="form-section">
                    <h3><i class="fas fa-edit"></i> 商品信息</h3>
                    <div class="form-group">
                        <label for="productName">商品名称</label>
                        <input type="text" id="productName" class="form-control" placeholder="AI将自动识别，您也可以手动修改">
                    </div>
                    <div class="form-group">
                        <label for="productDescription">商品描述（俄文）</label>
                        <textarea id="productDescription" class="form-control" rows="4" placeholder="AI将根据图片生成俄文描述，您也可以手动编辑"></textarea>
                    </div>
                    <div class="form-group">
                        <label for="outputFormat">输出格式</label>
                        <select id="outputFormat" class="form-control">
                            <option value="image">图片格式 (PNG)</option>
                            <option value="html">HTML格式</option>
                        </select>
                    </div>
                </div>
                
                <!-- 品牌水印设置 -->
                <div class="form-section">
                    <h3><i class="fas fa-copyright"></i> 品牌水印设置</h3>
                    <div class="watermark-section">
                        <div class="form-row">
                            <div class="form-group">
                                <label for="brandName">品牌名称</label>
                                <input type="text" id="brandName" class="form-control" placeholder="输入您的品牌名称" oninput="updateWatermarkPreview()">
                            </div>
                            <div class="form-group">
                                <label for="watermarkStyle">水印样式</label>
                                <select id="watermarkStyle" class="form-control" onchange="updateWatermarkPreview()">
                                    <option value="modern">现代简约</option>
                                    <option value="elegant">优雅经典</option>
                                    <option value="bold">粗体醒目</option>
                                    <option value="minimal">极简风格</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label>水印预览</label>
                            <div class="watermark-preview" id="watermarkPreview">
                                <span class="watermark-text" id="watermarkText">品牌名称</span>
                            </div>
                        </div>
                    </div>
                </div>
                
                <button class="generate-btn" onclick="generateProductDetail()" id="generateBtn" disabled>
                    <i class="fas fa-magic"></i> 生成产品详情页
                </button>
                
                <div class="loading" id="loading">
                    <div class="loading-spinner"></div>
                    <p>AI正在分析图片并生成产品详情页...</p>
                </div>
                
                <!-- 生成结果 -->
                <div class="result-section" id="resultSection">
                    <h3><i class="fas fa-file-alt"></i> 生成的产品详情页</h3>
                    <div class="product-detail-page" id="productDetailPage">
                        <!-- 动态生成的产品详情页内容 -->
                    </div>
                    
                    <div class="result-actions">
                        <button class="btn btn-primary" onclick="downloadHTML()">
                            <i class="fas fa-download"></i> 下载HTML
                        </button>
                        <button class="btn btn-secondary" onclick="copyHTML()">
                            <i class="fas fa-copy"></i> 复制代码
                        </button>
                        <button class="btn btn-primary" onclick="previewFullscreen()">
                            <i class="fas fa-expand"></i> 全屏预览
                        </button>
                        <button class="btn btn-secondary" onclick="generateAnother()">
                            <i class="fas fa-redo"></i> 重新生成
                        </button>
                    </div>
                </div>
            </div>
        </div>
    </div>
    
    <div id="toast" class="toast"></div>

    <script>
        let uploadedImages = [];
        let generatedHTML = '';
        let currentImageIndex = 0;
        
        // 批量文件上传处理
        function handleFileUpload(event) {
            const files = Array.from(event.target.files);
            if (files.length === 0) return;
            
            uploadedImages = [];
            let loadedCount = 0;
            
            files.forEach((file, index) => {
                if (!file.type.startsWith('image/')) {
                    showToast(`文件 ${file.name} 不是图片格式`);
                    return;
                }
                
                const reader = new FileReader();
                reader.onload = function(e) {
                    uploadedImages.push({
                        data: e.target.result,
                        file: file,
                        name: file.name
                    });
                    
                    loadedCount++;
                    if (loadedCount === files.length) {
                        // 显示第一张图片预览
                        if (uploadedImages.length > 0) {
                            document.getElementById('uploadedImage').src = uploadedImages[0].data;
                            document.getElementById('previewSection').style.display = 'block';
                            document.getElementById('generateBtn').disabled = false;
                            
                            // AI图像识别第一张图片
                            analyzeImage(uploadedImages[0].file);
                            
                            showToast(`成功上传 ${uploadedImages.length} 张图片，AI正在分析...`);
                        }
                    }
                };
                reader.readAsDataURL(file);
            });
        }
        
        // 拖拽上传
        const uploadArea = document.getElementById('uploadArea');
        
        uploadArea.addEventListener('dragover', function(e) {
            e.preventDefault();
            uploadArea.classList.add('dragover');
        });
        
        uploadArea.addEventListener('dragleave', function(e) {
            e.preventDefault();
            uploadArea.classList.remove('dragover');
        });
        
        uploadArea.addEventListener('drop', function(e) {
            e.preventDefault();
            uploadArea.classList.remove('dragover');
            
            const files = e.dataTransfer.files;
            if (files.length > 0) {
                document.getElementById('fileInput').files = files;
                handleFileUpload({ target: { files: files } });
            }
        });
        
        // AI图像识别（模拟）
        async function analyzeImage(file) {
            // 模拟AI分析延迟
            await new Promise(resolve => setTimeout(resolve, 2000));
            
            // 根据文件名或随机生成商品信息（俄文）
            const productTypes = [
                { name: 'Беспроводные Bluetooth наушники', desc: 'Высококачественный звук, удобная посадка, длительное время работы, подходят для спорта и повседневного использования' },
                { name: 'Умный чехол для телефона', desc: 'Изготовлен из качественных материалов, идеально подходит, эффективно защищает телефон, стильный внешний вид' },
                { name: 'Спортивная бутылка для воды', desc: 'Пищевой материал, сохраняет тепло и холод, портативный дизайн, подходит для спорта и фитнеса' },
                { name: 'Модный рюкзак', desc: 'Большая вместимость, многофункциональные отделения, прочный материал, подходит для ежедневных поездок и путешествий' },
                { name: 'Увлажняющий крем для лица', desc: 'Натуральные ингредиенты, глубокое увлажнение, улучшает текстуру кожи, подходит для всех типов кожи' }
            ];
            
            const randomProduct = productTypes[Math.floor(Math.random() * productTypes.length)];
            
            document.getElementById('productName').value = randomProduct.name;
            document.getElementById('productDescription').value = randomProduct.desc;
            
            showToast('AI图像分析完成！');
        }
        
        // 更新水印预览
        function updateWatermarkPreview() {
            const brandName = document.getElementById('brandName').value || '品牌名称';
            const style = document.getElementById('watermarkStyle').value;
            const watermarkText = document.getElementById('watermarkText');
            const watermarkPreview = document.getElementById('watermarkPreview');
            
            watermarkText.textContent = brandName;
            
            // 根据样式更新水印外观
            const styles = {
                modern: {
                    background: 'linear-gradient(135deg, #667eea, #764ba2)',
                    borderRadius: '20px',
                    fontSize: '14px',
                    fontWeight: 'bold'
                },
                elegant: {
                    background: 'linear-gradient(135deg, #2c3e50, #34495e)',
                    borderRadius: '5px',
                    fontSize: '16px',
                    fontWeight: '500'
                },
                bold: {
                    background: 'linear-gradient(135deg, #e74c3c, #c0392b)',
                    borderRadius: '10px',
                    fontSize: '16px',
                    fontWeight: '900'
                },
                minimal: {
                    background: 'rgba(0, 0, 0, 0.7)',
                    borderRadius: '3px',
                    fontSize: '12px',
                    fontWeight: '400'
                }
            };
            
            const selectedStyle = styles[style];
            Object.assign(watermarkPreview.style, {
                background: selectedStyle.background,
                borderRadius: selectedStyle.borderRadius
            });
            
            Object.assign(watermarkText.style, {
                fontSize: selectedStyle.fontSize,
                fontWeight: selectedStyle.fontWeight
            });
        }
        
        // 生成产品详情页
        async function generateProductDetail() {
            const productName = document.getElementById('productName').value.trim();
            const productDescription = document.getElementById('productDescription').value.trim();
            const brandName = document.getElementById('brandName').value.trim();
            const outputFormat = document.getElementById('outputFormat').value;
            
            if (!productName) {
                showToast('请输入商品名称');
                return;
            }
            
            if (!brandName) {
                showToast('请输入品牌名称');
                return;
            }
            
            if (uploadedImages.length === 0) {
                showToast('请先上传商品图片');
                return;
            }
            
            // 显示加载状态
            document.getElementById('generateBtn').disabled = true;
            document.getElementById('loading').style.display = 'block';
            document.getElementById('resultSection').style.display = 'none';
            
            try {
                // 模拟AI生成过程
                await new Promise(resolve => setTimeout(resolve, 3000));
                
                if (outputFormat === 'image') {
                    // 批量生成图片格式
                    await generateBatchImages({
                        name: productName,
                        description: productDescription,
                        brand: brandName
                    });
                } else {
                    // 生成HTML格式（仅第一张图片）
                    const features = generateProductFeatures(productName);
                    const detailPageHTML = generateDetailPageHTML({
                        name: productName,
                        description: productDescription,
                        brand: brandName,
                        image: uploadedImages[0].data,
                        features: features
                    });
                    
                    document.getElementById('productDetailPage').innerHTML = detailPageHTML;
                    document.getElementById('resultSection').style.display = 'block';
                    generatedHTML = generateFullHTML(detailPageHTML);
                }
                
                showToast('产品详情页生成成功！');
            } catch (error) {
                console.error('生成失败:', error);
                showToast('生成失败，请重试');
            } finally {
                document.getElementById('generateBtn').disabled = false;
                document.getElementById('loading').style.display = 'none';
            }
        }
        
        // 生成产品特性
        function generateProductFeatures(productName) {
            const commonFeatures = [
                '高品质材料制作',
                '精工细作工艺',
                '人性化设计',
                '性价比超高',
                '售后服务保障'
            ];
            
            const specificFeatures = {
                '耳机': ['高保真音质', '降噪技术', '长续航', '舒适佩戴'],
                '手机': ['高清屏幕', '强劲性能', '优质摄像', '快速充电'],
                '水杯': ['保温保冷', '食品级材质', '防漏设计', '便携轻便'],
                '背包': ['大容量', '多分层', '耐磨材质', '人体工学'],
                '护肤': ['天然成分', '温和无刺激', '深层滋润', '快速吸收']
            };
            
            let features = [...commonFeatures];
            
            // 根据产品名称添加特定特性
            for (const [key, values] of Object.entries(specificFeatures)) {
                if (productName.includes(key)) {
                    features = [...values, ...commonFeatures.slice(0, 2)];
                    break;
                }
            }
            
            return features.slice(0, 5);
        }
        
        // 批量生成图片格式
        async function generateBatchImages(productInfo) {
            const resultSection = document.getElementById('resultSection');
            const productDetailPage = document.getElementById('productDetailPage');
            
            let imagesHTML = '<div class="batch-images-container">';
            imagesHTML += `<h3><i class="fas fa-images"></i> 批量生成结果 (${uploadedImages.length} 张图片)</h3>`;
            
            for (let i = 0; i < uploadedImages.length; i++) {
                const imageData = uploadedImages[i];
                const canvas = await generateProductImageCanvas({
                    ...productInfo,
                    image: imageData.data,
                    imageName: imageData.name
                });
                
                const imageUrl = canvas.toDataURL('image/png');
                
                imagesHTML += `
                    <div class="generated-image-item">
                        <h4>图片 ${i + 1}: ${imageData.name}</h4>
                        <img src="${imageUrl}" alt="生成的产品详情图" class="generated-image">
                        <div class="image-actions">
                            <button class="btn btn-primary" onclick="downloadImage('${imageUrl}', '${productInfo.name}_${i + 1}.png')">
                                <i class="fas fa-download"></i> 下载
                            </button>
                        </div>
                    </div>
                `;
            }
            
            imagesHTML += '</div>';
            productDetailPage.innerHTML = imagesHTML;
            resultSection.style.display = 'block';
        }
        
        // 生成产品图片Canvas
        async function generateProductImageCanvas(product) {
            const canvas = document.createElement('canvas');
            const ctx = canvas.getContext('2d');
            
            // 设置画布尺寸
            canvas.width = 800;
            canvas.height = 1000;
            
            // 背景
            ctx.fillStyle = '#ffffff';
            ctx.fillRect(0, 0, canvas.width, canvas.height);
            
            // 品牌水印
            const watermarkStyle = document.getElementById('watermarkStyle').value;
            ctx.save();
            ctx.fillStyle = '#667eea';
            ctx.font = 'bold 24px Arial';
            ctx.fillText(product.brand, 30, 50);
            ctx.restore();
            
            // 加载并绘制商品图片（保持原始比例）
            const img = new Image();
            await new Promise((resolve) => {
                img.onload = () => {
                    // 计算保持比例的尺寸
                    const maxWidth = 400;
                    const maxHeight = 400;
                    let imgWidth = img.width;
                    let imgHeight = img.height;
                    
                    // 按比例缩放
                    if (imgWidth > maxWidth || imgHeight > maxHeight) {
                        const ratio = Math.min(maxWidth / imgWidth, maxHeight / imgHeight);
                        imgWidth = imgWidth * ratio;
                        imgHeight = imgHeight * ratio;
                    }
                    
                    const x = (canvas.width - imgWidth) / 2;
                    const y = 100 + (maxHeight - imgHeight) / 2; // 垂直居中
                    
                    ctx.drawImage(img, x, y, imgWidth, imgHeight);
                    resolve();
                };
                img.src = product.image;
            });
            
            // 商品名称
            ctx.fillStyle = '#333';
            ctx.font = 'bold 32px Arial';
            ctx.textAlign = 'center';
            const nameY = 550;
            wrapText(ctx, product.name, canvas.width / 2, nameY, canvas.width - 60, 40);
            
            // 商品描述
            ctx.fillStyle = '#666';
            ctx.font = '18px Arial';
            const descY = nameY + 80;
            wrapText(ctx, product.description, canvas.width / 2, descY, canvas.width - 60, 25);
            
            return canvas;
        }
        
        // 文本换行函数
        function wrapText(ctx, text, x, y, maxWidth, lineHeight) {
            const words = text.split(' ');
            let line = '';
            let currentY = y;
            
            for (let n = 0; n < words.length; n++) {
                const testLine = line + words[n] + ' ';
                const metrics = ctx.measureText(testLine);
                const testWidth = metrics.width;
                
                if (testWidth > maxWidth && n > 0) {
                    ctx.fillText(line, x, currentY);
                    line = words[n] + ' ';
                    currentY += lineHeight;
                } else {
                    line = testLine;
                }
            }
            ctx.fillText(line, x, currentY);
        }
        
        // 下载图片
        function downloadImage(dataUrl, filename) {
            const link = document.createElement('a');
            link.download = filename;
            link.href = dataUrl;
            document.body.appendChild(link);
            link.click();
            document.body.removeChild(link);
            showToast('图片下载成功！');
        }
        
        // 生成详情页HTML（移除价格）
        function generateDetailPageHTML(product) {
            const watermarkStyle = document.getElementById('watermarkStyle').value;
            const watermarkStyles = {
                modern: 'background: linear-gradient(135deg, #667eea, #764ba2); border-radius: 20px; font-weight: bold;',
                elegant: 'background: linear-gradient(135deg, #2c3e50, #34495e); border-radius: 5px; font-weight: 500;',
                bold: 'background: linear-gradient(135deg, #e74c3c, #c0392b); border-radius: 10px; font-weight: 900;',
                minimal: 'background: rgba(0, 0, 0, 0.7); border-radius: 3px; font-weight: 400;'
            };
            
            const featuresHTML = product.features.map(feature => 
                `<div class="feature-item"><i class="fas fa-check"></i>${feature}</div>`
            ).join('');
            
            return `
                <div class="product-header">
                    <div class="brand-watermark" style="${watermarkStyles[watermarkStyle]}">
                        ${product.brand}
                    </div>
                </div>
                <div class="product-content">
                    <div class="product-image-container">
                        <img src="${product.image}" alt="${product.name}" class="product-image">
                    </div>
                    <div class="product-info">
                        <h1 class="product-title">${product.name}</h1>
                        <div class="product-description">${product.description}</div>
                        <div class="product-features">
                            <h4 style="margin-bottom: 15px; color: #333;"><i class="fas fa-star" style="color: #ffc107; margin-right: 8px;"></i>Особенности продукта</h4>
                            ${featuresHTML}
                        </div>
                        <div class="action-buttons">
                            <button class="btn btn-primary">
                                <i class="fas fa-shopping-cart"></i> Купить сейчас
                            </button>
                            <button class="btn btn-secondary">
                                <i class="fas fa-heart"></i> В избранное
                            </button>
                        </div>
                    </div>
                </div>
            `;
        }
        
        // 生成完整的HTML文件（移除价格相关样式）
        function generateFullHTML(contentHTML) {
            return `<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>${document.getElementById('productName').value} - Детали продукта</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        body { font-family: 'Arial', sans-serif; margin: 0; padding: 20px; background-color: #f5f5f5; }
        .product-detail-page { background: white; border-radius: 15px; box-shadow: 0 10px 30px rgba(0,0,0,0.1); overflow: hidden; max-width: 1200px; margin: 0 auto; }
        .product-header { background: linear-gradient(135deg, #f8f9fa, #e9ecef); padding: 30px; position: relative; }
        .brand-watermark { position: absolute; top: 20px; left: 20px; color: white; padding: 8px 15px; border-radius: 20px; font-weight: bold; font-size: 14px; backdrop-filter: blur(10px); box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3); }
        .product-content { display: grid; grid-template-columns: 1fr 1fr; gap: 40px; padding: 40px; }
        .product-image-container { text-align: center; }
        .product-image { max-width: 100%; border-radius: 15px; box-shadow: 0 10px 30px rgba(0,0,0,0.2); }
        .product-info { padding: 20px 0; }
        .product-title { font-size: 28px; font-weight: 700; color: #333; margin-bottom: 15px; line-height: 1.3; }
        .product-description { font-size: 16px; line-height: 1.6; color: #666; margin-bottom: 25px; }
        .product-features { background-color: #f8f9fa; padding: 20px; border-radius: 10px; margin-bottom: 25px; }
        .feature-item { display: flex; align-items: center; margin-bottom: 10px; font-size: 14px; }
        .feature-item i { color: #28a745; margin-right: 10px; width: 16px; }
        .action-buttons { display: flex; gap: 15px; margin-top: 30px; }
        .btn { padding: 12px 25px; border: none; border-radius: 8px; font-size: 16px; font-weight: 600; cursor: pointer; transition: all 0.3s; text-decoration: none; display: inline-flex; align-items: center; gap: 8px; }
        .btn-primary { background: linear-gradient(135deg, #667eea, #764ba2); color: white; }
        .btn-primary:hover { transform: translateY(-2px); box-shadow: 0 8px 20px rgba(102, 126, 234, 0.3); }
        .btn-secondary { background-color: #6c757d; color: white; }
        .btn-secondary:hover { background-color: #5a6268; }
        @media (max-width: 768px) { .product-content { grid-template-columns: 1fr; gap: 20px; } .action-buttons { flex-direction: column; } }
    </style>
</head>
<body>
    <div class="product-detail-page">
        ${contentHTML}
    </div>
</body>
</html>`;
        }
        
        // 下载HTML文件
        function downloadHTML() {
            const blob = new Blob([generatedHTML], { type: 'text/html' });
            const url = URL.createObjectURL(blob);
            const a = document.createElement('a');
            a.href = url;
            a.download = `${document.getElementById('productName').value}_详情页.html`;
            document.body.appendChild(a);
            a.click();
            document.body.removeChild(a);
            URL.revokeObjectURL(url);
            showToast('HTML文件下载成功！');
        }
        
        // 复制HTML代码
        function copyHTML() {
            navigator.clipboard.writeText(generatedHTML).then(() => {
                showToast('HTML代码已复制到剪贴板！');
            }).catch(error => {
                console.error('复制失败:', error);
                showToast('复制失败，请手动复制');
            });
        }
        
        // 全屏预览
        function previewFullscreen() {
            const newWindow = window.open('', '_blank');
            newWindow.document.write(generatedHTML);
            newWindow.document.close();
        }
        
        // 重新生成
        function generateAnother() {
            document.getElementById('resultSection').style.display = 'none';
            document.getElementById('previewSection').style.display = 'none';
            document.getElementById('generateBtn').disabled = true;
            document.getElementById('fileInput').value = '';
            document.getElementById('productName').value = '';
            document.getElementById('productDescription').value = '';
            uploadedImages = [];
            currentImageIndex = 0;
            generatedHTML = '';
            window.scrollTo({ top: 0, behavior: 'smooth' });
        }
        
        // 显示提示信息
        function showToast(message, duration = 3000) {
            const toast = document.getElementById('toast');
            toast.textContent = message;
            toast.classList.add('show');
            
            setTimeout(() => {
                toast.classList.remove('show');
            }, duration);
        }
        
        // 页面加载完成后的初始化
        document.addEventListener('DOMContentLoaded', function() {
            updateWatermarkPreview();
            showToast('欢迎使用AI产品详情页生成工具！', 2000);
        });
    </script>
</body>
</html>